package com.wxy.ej.flow.modules.taskflow.dto;

import lombok.Data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
public class DataDto {

    private long taskFlowId = 0l;

    // 执行日志
    private List<String> logList = new ArrayList<>();

    // ========= 控制循环 =======
    private boolean inCircle = false;
    private boolean isBreak = false;
    private boolean isContinue = false;
    //private Integer currentCircleIndex = null; // 当前下标
    //private Map<String, Object> currentCircleItemData = null; // 当前数据
    // 重置
    public void resetCircleInfo(String indexKey, String itemVar) {
        this.setInCircle(false);
        this.setBreak(false);
        this.setContinue(false);
        this.storageControllerVarMap.remove(indexKey);
        this.storageDataVarMap.remove(itemVar);
    }


    // ======== 变量存储在这里 =======
    // 数据变量，与页面交互
    private Map<String, Object> storageDataVarMap = new HashMap<>();
    // 控制用的变量，不参与页面交互
    // 如：记录结束节点执行次数
    private Map<String, Object> storageControllerVarMap = new HashMap<>();
    public Object getValueFromMap(String key, Map<String, Object> map) {
        Object value =  map.get(key);
        if (value==null) {
            map.put(key, 0);
        }
        return map.get(key);
    }

    // UI交互：StartNode: 入参数据对象
    private Object uiInParam;
    private Object uiOutData;
    private Object uiOutData4PageTotal;

    // ======== 清空所有，结束节点调用 ========
    public void clear() {
        //currentCircleItemData = null;
        storageControllerVarMap.clear();
        storageControllerVarMap = null;
        uiInParam = null;
    }


}
